package com.aaa.qy127.controller;

import com.aaa.qy127.entity.Role;
import com.aaa.qy127.service.RoleService;
import com.aaa.qy127.util.CodeAndMsg;
import com.aaa.qy127.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RequestMapping("/role")
@RestController
public class RoleController {

    @Resource(name = "roleServiceImpl")
    private RoleService roleService;

    /**
     * 查询 所有的 role 信息  插入到 staff 表中的 角色下拉框中
     * @return
     */
    @RequestMapping("/selectRole")
    public  List<Map<String, Object>> selectRole(){
        List<Map<String, Object>> maps = roleService.selRole();
        return maps;
    }

    /**
     * 查询所有的 role 信息 返回到  role 表中
     * @return
     */
    @RequestMapping("/selectAllRole")
    public Result selectAllRole(){
        Result result = roleService.selAllRole();
        return result;
    }

    /**
     * 添加 或者 修改 role 信息
     */
    @RequestMapping("/updateAndInsertRole")
    public CodeAndMsg updateAndInsertRole(Role role){
        CodeAndMsg codeAndMsg = roleService.insertAndUpdate(role);
        return codeAndMsg;
    }

    /**
     * 删除一条 role 数据
     * @return
     */
    @RequestMapping("/deleteRole")
    public CodeAndMsg deleteRole(String rid){
        CodeAndMsg codeAndMsg = roleService.deleteRole(rid);
        return codeAndMsg;
    }
}
